<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        * {
            padding: 0;
            margin: 0;
        }

        .la {
            width: 700px;
            height: 100px;
            border: 1px solid red;
            display: flex;
        }

        .xiao {
            text-align: center;
            margin: 5px 7px;
        }
        .ye{
            display: inline-block;
        }
    </style>
</head>

<body>
    <div class="la"></div>
    <button class="shang">上一页</button>
    <button class="xia">下一页</button>
    <div class="ye">1/4</div>
</body>

</html>
<script>
    var page = 1
    function ajax1(med, url, can, han) {
        var xhr = new XMLHttpRequest()
        xhr.open(med, url + '?' + canshu(can))
        xhr.onreadystatechange = function () {
            if (xhr.readyState == 4) {
                han(JSON.parse(xhr.responseText))
            }
        }
        xhr.send()
    }
    function canshu(can) {
        var str = ''
        for (const key in can) {
            str += `${key}=${can[key]}&`
        }
        return str.slice(0, str.length - 1)
    }
    function xuanran(){
        ajax1('get', `https://yantianfeng.com/api/emotion`, { page: page, count: 10 }, function (data) {
            var div = data.emotions.map((item, index) => {
                return `
            <div class="xiao">
             <div><img src="${item.url}"></div>
             <div>${item.title}</div>
             </div>
        `
            }).join('')
            document.querySelector('.la').innerHTML = div
            document.querySelector('.ye').innerHTML=`${page}/4`
        })
    }
    xuanran()
    document.querySelector('.shang').onclick = function () {
        if(page>1){
            page--
            xuanran()
        }
    }
    document.querySelector('.xia').onclick = function () {
        if(page<4){
            page++
            xuanran()
        }
    }


</script>